using UnityEngine;
using Framework;

namespace GameCore
{
    public abstract class Cell : MonoBehaviour
    {
        public Inventory inventory;
        public Vector3 offset = new(0.5f, 0.5f, -0.001f);
        public Vector2Int gridPos;

        public void PlaceItem(GridItem item)
        {
            inventory.PlaceItem(gridPos, item);
        }

        #region Display
        public SpriteRenderer sr;
        public Color normalColor = Color.white.Alpha(0.3f);
        public Color successColor = Color.green.Alpha(0.5f);
        public Color errorColor = Color.red.Alpha(0.5f);
        private void Start()
        {
            SetNormal();
        }
        
        public void Show()
        {
            gameObject.SetActive(true);
        }

        public void Hide()
        {
            gameObject.SetActive(false);
        }

        public void SetNormal()
        {
            sr.color = normalColor;
        }

        public void SetSuccess()
        {
            sr.color = successColor;
        }

        public void SetError()
        {
            sr.color = errorColor;
        }
        
        #endregion

        
        #region Mouse Interaction
        private void OnMouseEnter()
        {
            PlayerInputHandler.SetHoveringCell(this);
        }

        private void OnMouseExit()
        {
            PlayerInputHandler.ClearHoveringCell(this);
        }

        public abstract bool TryPlaceItem(GridItem item);
        public abstract void OnClick();

        #endregion
    }
}